package com.mazaiting.classfile.attr.info;

import com.mazaiting.classfile.ClassReader;
import com.mazaiting.classfile.attr.entity.TypeAnnotationEntity;
import com.mazaiting.classfile.constant.ConstantPool;
import lombok.ToString;

import java.util.Arrays;

/**
 * 运行时不可见类型注解属性
 *
 * @author mazaiting
 * @since 2021/8/13
 */
public class RuntimeInvisibleTypeAnnotationsAttribute extends AttributeInfo{
    /**
     * 注解数 无符号 u2
     */
    private int numAnnotations;
    /**
     * 类型注解
     */
    private TypeAnnotationEntity[] annotations;

    public RuntimeInvisibleTypeAnnotationsAttribute(ConstantPool pool, int index, int length) {
        super(pool, index, length);
    }

    @Override
    public void readInfo(ClassReader reader) {
        this.numAnnotations = reader.readU2ToUnsignedShort();
        this.annotations = new TypeAnnotationEntity[numAnnotations];
        for (int i = 0; i < numAnnotations; i++) {
            this.annotations[i] = new TypeAnnotationEntity(reader, pool);
        }
    }

    @Override
    public String toString() {
        return "RuntimeInvisibleTypeAnnotationsAttribute{" +
                "nameIndex=" + nameIndex +
                ", length=" + length +
                ", numAnnotations=" + numAnnotations +
                ", annotations=" + Arrays.toString(annotations) +
                '}';
    }
}


















